package com.zry.fertilizer.ui.activity

import android.annotation.SuppressLint
import com.zry.fertilizer.R
import com.zry.fertilizer.been.ResultBean
import com.zry.fertilizer.been.TraceCodeBean
import com.zry.fertilizer.databinding.ActivityTracingCodeInfoBinding
import com.zry.fertilizer.retrofit.HttpServer
import com.zry.fertilizer.retrofit.ShowUserView
import com.zry.fertilizer.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_tracing_code_info.*
import kotlinx.android.synthetic.main.common_title.*

class TracingCodeInfoActivity : BaseActivity(), ShowUserView {

    private var title = ""
    private var longCode = ""
    private var tracingCodeInfoBinding: ActivityTracingCodeInfoBinding? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_tracing_code_info
    }

    override fun initData() {
        title = intent.getStringExtra("title")
        longCode = intent.getStringExtra("longCode")
        titleCenterText.text = "追溯码详情"
        commonLeftLinearLayout.setOnClickListener { finish() }
        tracingCodeInfoBinding = viewDataBinding as ActivityTracingCodeInfoBinding

        HttpServer(this).getCodeInfo(longCode, this)
    }

    @SuppressLint("SetTextI18n")
    override fun toMainActivity(what: Int, data: Any) {
        when (what) {
            39 -> {
                val resultData = data as ResultBean<TraceCodeBean>
                if (resultData.State == "1") {
                    tracingCodeInfoBinding?.traceCodeBean = resultData.ResultData

                    when (resultData.ResultData.StateID) {
                        "1" -> traceCodeInfoModelTV.text = "手动入库"
                        "2" -> traceCodeInfoModelTV.text = "自动入库"
                        "0" -> traceCodeInfoModelTV.text = ""
                    }
                    when (resultData.ResultData.StoreType) {
                        "1" -> traceCodeInfoTypeTV.text = "单码入库"
                        "2" -> traceCodeInfoTypeTV.text = "二级码入库"
                        "3" -> traceCodeInfoTypeTV.text = "三级码入库"
                        "0" -> traceCodeInfoTypeTV.text = ""
                    }
                    when (resultData.ResultData.OutStateID) {
                        "1" -> outTraceTypeTV.text = "手动出库"
                        "2" -> outTraceTypeTV.text = "自动出库"
                        "0" -> outTraceTypeTV.text = ""
                    }
                    when (resultData.ResultData.OutType) {
                        "1" -> outTraceStateTypeTV.text = "单码出库"
                        "2" -> outTraceStateTypeTV.text = "二级码出库"
                        "3" -> outTraceStateTypeTV.text = "三级码出库"
                        "0" -> outTraceStateTypeTV.text = ""
                    }
                    traceCodeExpiryDateTV.text = resultData.ResultData.ExpiryDate + "月"
                } else {
                    toast(resultData.Message)
                }
            }
        }
    }
}
